package com.xiaotu.iterator;

import java.util.Iterator;

/**
 * @author 张晓
 * @create 2020-06-25 17:20
 */
public class ComputerColleageIterator implements Iterator {

    //这里我们需要知道Department 是以怎样的方式存放
    Department[] departments;
    int position = 0;//遍历的位置

    public ComputerColleageIterator(Department[] departments) {
        this.departments = departments;
    }

    //判断是否还有下一个元素
    @Override
    public boolean hasNext() {
        if (position >= departments.length || departments[position] == null) {
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Object next() {
        Department department = departments[position];
        position++;
        return department;
    }

    //删除的方法，默认空实现
    @Override
    public void remove() {

    }
}
